package com.ruoyi.business.controller;

import com.ruoyi.business.domain.RawMatter;
import com.ruoyi.business.service.RawMatterService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * @author JerryLu
 * @date 2024/8/4 16:57
 * @description 物料原材料类别控制器
 */
@RestController
@RequestMapping("/system/raw_matter")
public class RawMatterController extends BaseController {
    @Autowired
    private RawMatterService rawMatterService;

    /**
     * 查询原材料类别列表
     */
//    @PreAuthorize("@ss.hasPermi('system:matter:list')")
    @GetMapping("/list")
    public TableDataInfo list(RawMatter rawMatter)
    {
        startPage();
        List<RawMatter> list = rawMatterService.queryList(rawMatter);
        return getDataTable(list);
    }

    /**
     * 导出原材料类别列表
     */
//    @PreAuthorize("@ss.hasPermi('system:matter:export')")
    @Log(title = "原材料类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RawMatter rawMatter)
    {
        List<RawMatter> list = rawMatterService.queryList(rawMatter);
        ExcelUtil<RawMatter> util = new ExcelUtil<RawMatter>(RawMatter.class);
        util.exportExcel(response, list, "原材料类别数据");
    }

    /**
     * 获取原材料类别详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:matter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rawMatterService.getById(id));
    }

    /**
     * 新增原材料类别
     */
//    @PreAuthorize("@ss.hasPermi('system:matter:add')")
    @Log(title = "原材料类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RawMatter rawMatter)
    {
        return toAjax(rawMatterService.save(rawMatter));
    }

    /**
     * 修改原材料类别
     */
//    @PreAuthorize("@ss.hasPermi('system:matter:edit')")
    @Log(title = "原材料类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RawMatter rawMatter)
    {
        return toAjax(rawMatterService.updateById(rawMatter));
    }

    /**
     * 删除原材料类别
     */
//    @PreAuthorize("@ss.hasPermi('system:matter:remove')")
    @Log(title = "原材料类别", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rawMatterService.removeByIds(Arrays.asList(ids)));
    }
}
